/*
  Creator: Kisamin Resident and copyright by her.  All rights reserved except those specifically set forth here:
  You may:
  	Use these scripts in any project
	Modify these scripts in any way you wish subject to:
		1. Retaining this set of comments
		2. Explicity commenting and showing any changes you might make
	You may NOT:
	License these scripts to someone else with restrictions differing from the above.
	Charge a fee for the scripts themselves (although you may charge for an object that
		utilizes these scripts to add functionality)
	Charge a fee for any "library" or "collection" of scripts that includes this script.

If you have questions about your rights under this coment and/or the Gnu CopyLeft, please request further information
and/or explicit permission from Kisamin Resident

This script is to be placed in the rezzed "killer" script that the DamageCore rezzes on a per-victim basis.
*/

key g_kVictim;

integer g_iListenerHandle = 0;

vector k_vExplosionSize = <10., 10., 10.>;

doKill () {
  list l_lObjectData = llGetObjectDetails (g_kVictim, [OBJECT_POS]);
  if (llGetListLength (l_lObjectData) == 0) {
	//	llOwnerSay ("Target not in sim.");
	llDie ();
  }
  
  vector l_vObjectLocation = llList2Vector (l_lObjectData, 0);
  integer i;
  integer l_iNumMoves = ((integer)(llVecDist (llGetRootPosition (), l_vObjectLocation) / 9.0)) + 1;
  list l_lObjectMovementParams;
  for (i=0; i<l_iNumMoves; i++)
	l_lObjectMovementParams += [PRIM_POSITION, l_vObjectLocation];
  llSetDamage (llGetStartParameter ());
  llSetPrimitiveParams ([PRIM_PHYSICS, FALSE]
						+ l_lObjectMovementParams
						+ [
						   PRIM_PHYSICS, TRUE
						   , PRIM_TEMP_ON_REZ, TRUE
						   , PRIM_PHANTOM, FALSE
						   , PRIM_SIZE, k_vExplosionSize
						   ]);
  llSensor ( "", g_kVictim, AGENT, 40., PI);
}



default {

   on_rez (integer in_iParam) {
	 if (in_iParam) {
	   // Code for being launched
	   g_iListenerHandle = llListen ((integer)("0x" + llGetSubString ((string)llGetKey (), 0, 7)), "", NULL_KEY, "");
	   llSetTimerEvent (30.);
	 } else {
	   // Code if we're merely rezzed and tinkering with it
		 if (g_iListenerHandle)
		   llListenRemove (g_iListenerHandle);
		 llSetTimerEvent (0.);
	 }
   }

   changed (integer in_iChange) {
	 if (in_iChange & CHANGED_INVENTORY)
	   llResetScript ();
   }

   listen (integer in_iChannel, string in_sSpeaker, key in_kSpeaker, string in_sMessage) {
	 g_kVictim = (key) in_sMessage;
	 llSetTimerEvent (5.);
	 doKill ();
   }
   
   timer () {
	 llDie ();
   }

   no_sensor () {
	 llDie ();
   }
   
   sensor (integer in_iNumSensed) {
	 doKill ();
   }

   collision_start (integer in_iNumColliders) {
	 doKill ();
   }
   
   land_collision (vector in_vPosition) {
	 doKill ();
   }
}
